﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Diagnostics;

namespace ORMAC.Core
{
    public static class DataRowExtension
    {
        public static string GetRowHashCode<T>(this DataRow dataRow,string tableName){
            IEnumerable<string> pKeys = ReflectionHelper.GetPrimaryKeys<T>(tableName, string.Empty);
            return dataRow.GetUniqueID(pKeys);
            //string hash = string.Empty;
            //foreach (var item in dataRow.ItemArray)
            //{
            //    hash += item.ToString().GetHashCode();
            //};
            //return hash;
        }
        public static  string GetUniqueID(this DataRow item,IEnumerable<string> primaryKeys)
        {
            string hash = string.Empty;
            foreach (var primaryKey in primaryKeys)
                hash += item[primaryKey].ToString();
            return hash;
        }

    }
}
